package com.origin.opengles_ndk.dialog.type_list

import android.content.Context
import android.util.Log
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.origin.baselibrary.activity.BaseActivity
import com.origin.opengles_ndk.R
import com.origin.opengles_ndk.bean.TypeBean
import com.origin.opengles_ndk.dialog.type_list.adapter.TypeAdapter
import com.origin.uilibrary.dailog.bese.BaseDialog
import com.origin.uilibrary.xrecycleview.adapter.BaseRecycleAdapter

class TypeListDialog : BaseDialog {
    private val typeBeans: MutableList<TypeBean> = mutableListOf()
    private val typeRecycler: RecyclerView by lazy {
        getView(R.id.typeRecycler)
    }
    private val typeAdapter: TypeAdapter by lazy {
        TypeAdapter(typeBeans, mContext)
    }

    constructor(context: Context) : super(context) {

    }

    override fun setUpLayoutId(): Int = R.layout.dialog_type_list
    override fun doAction() {
        super.doAction()
        initRecyclerView()
    }

    private fun initRecyclerView() {
//        typeRecycler.setPullRefreshEnabled(false)
        typeRecycler.layoutManager = LinearLayoutManager(mContext)
        typeAdapter.mItemClickListener = object : BaseRecycleAdapter.OnItemClickListener<TypeBean> {

            override fun onItemClick(position: Int,item:TypeBean, view: View?) {
                this@TypeListDialog.cancel()
                callDialogItem?.doCall(position)
            }

        }
        typeRecycler.adapter = typeAdapter
    }

    fun addAllTypeBeans(_typeBeans: MutableList<TypeBean>) {
        typeBeans.clear()
        typeBeans.addAll(_typeBeans)
        typeAdapter.notifyDataSetChanged()
    }

    interface CallDialogItem {
        fun doCall(position: Int)
    }

    var callDialogItem: CallDialogItem? = null
    fun setAdapterItemClick(onItemClickListener: CallDialogItem) {
        this@TypeListDialog.callDialogItem = onItemClickListener
    }

}